<?php

namespace App\Http\Controllers\WebApi\Business;


class ExportUsersBusiness extends SpreadSheetBase
{
    public function export($data = [])
    {
        $excelData = [];
        foreach ($data as $val) {
            array_push($excelData, [
                $val->nickname . "\t",
                self::getSex($val->sex),
                $val->personalized_signature . "\t",
                $val->phone . "\t",
                $val->created_at . "\t",
                $val->last_login_log->device ?? '',
                $val->last_login_log->created_at ?? '',
                $val->last_login_log->updated_at ?? '',
            ]);
        }
        $this->setName('识别明细.csv');
        $this->setHead(['昵称', '性别', '个性签名', '手机号', '注册时间', '最后登录设备', '登录时间', '退出时间']);
        $this->setData($excelData);
        parent::run();
    }

    public static function getSex($sex)
    {
        $res = '未知';
        switch ($sex) {
            case 1:
                $res = '男';
                break;
            case 2:
                $res = '女';
                break;
        }
        return $res;
    }
}
